package com.saint.farmshop.Service.ServiceImpl;

import com.saint.farmshop.Entity.Production;
import com.saint.farmshop.Entity.ProductionDetail;
import com.saint.farmshop.Entity.ProductionSecondType;
import com.saint.farmshop.Entity.ProductionType;
import com.saint.farmshop.Mapper.MapperImpl.ProductionMapperImpl;
import com.saint.farmshop.Service.ProductionService;
import com.saint.farmshop.Utils.Result;
import com.saint.farmshop.Utils.ResultCode;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 产品服务实现类
 *
 * @author Saint
 * @date 2022/05/23
 */
@Service
public class ProductionServiceImpl implements ProductionService {

    @Resource
    ProductionMapperImpl productionMapper;

    @Override
    public List<Production> getProductionByType(ProductionSecondType productionSecondType, Integer pageIndex, Integer pageSize) {
        return productionMapper.getProductionByType(productionSecondType.getId(),pageIndex,pageSize);
    }

    @Override
    public List<Production> getProductionByOpenId(String openId, Integer pageIndex, Integer pageSize) {
        return productionMapper.getProductionByOpenId(openId,pageIndex,pageSize);
    }

    @Override
    public Result releaseProduction(ProductionDetail productionDetail) {
        if(productionMapper.releaseProduction(productionDetail)) {
            return Result.ok();
        }
        else{
            return Result.RCode(false, ResultCode.ARTICLE_NOT_ADD);
        }
    }

    @Override
    public Result deleteProduction(ProductionDetail productionDetail) {
        if(productionMapper.deleteProduction(productionDetail)) {
            return Result.ok();
        }
        else{
            return Result.RCode(false, ResultCode.ARTICLE_NOT_ADD);
        }
    }

    @Override
    public List<Production> getProductionList(Integer pageIndex,Integer pageSize) {
        return productionMapper.getProductionList(pageIndex,pageSize);
    }
}
